package xzx.config;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className: CommonConfig
 * @author: xzx
 * @date: 2025-10-21
 **/
@Slf4j
@Configuration
@RequiredArgsConstructor
public class CommonConfig {
    /**
     * ChatMemory 聊天对话记忆的存储
     * @param jdbcChatMemoryRepository 操作数据库存储聊天记忆
     */
    @Bean
    public ChatMemory chatMemory(JdbcChatMemoryRepository jdbcChatMemoryRepository) {
        log.debug("ChatMemory 初始化...");
        return MessageWindowChatMemory.builder()
                .chatMemoryRepository(jdbcChatMemoryRepository) // 改动之处
                .maxMessages(20)
                .build();
    }
}
